<?php
require_once '../include.php';
checkLogin();#验证是否登录
$limit = 2;
$curr = isset($_REQUEST['curr']) ? (int)$_REQUEST['curr'] : 1;
$rows = getUserPage($curr,$limit);
$sql="select * from imooc_user";
$total = getResultNum($sql);
$page=ceil($total/$limit);
if (!$rows){
    alertMes('没有用户，请添加用户','addUser.php');
    exit();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>用户列表</title>
</head>
<link rel="stylesheet" href="style/backstage.css">
<body>
<div class="details">
    <h3>用户列表</h3><br>
    <div class="details_operation clearfix">
        <div class="bui_select">
            <input type="button" value="添&nbsp;&nbsp;加" class="add"  onclick="addUser()">
        </div>
        <!--表格-->
        <table class="table" cellspacing="1" cellpadding="1">
            <thead>
            <tr>
                <th width="15%">编号</th>
                <th width="25%">用户名称</th>
                <th width="20%">用户邮箱</th>
                <th width="20%">是否激活</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            <?php  foreach($rows as $row):?>
                <tr>
                    <!--这里的id和for里面的c1 需要循环出来-->
                    <td>
                        <input type="checkbox" id="c1" class="check">
                        <label for="c1" class="label"><?php echo $row['id'];?></label>
                    </td>
                    <td><?php echo $row['username'];?></td>
                    <td><?php echo $row['email'];?></td>
                    <td><?php echo $row['activeFlag']==0?'未激活':'已激活';?></td>
                    <td align="center">
                        <input type="button" value="修改" class="btn" onclick="editUser(<?php echo $row['id'];?>)">
                        <input type="button" value="删除" class="btn"  onclick="delUser(<?php echo $row['id'];?>)">
                    </td>
                </tr>
            <?php endforeach;?>
            <?php if($total>$limit):?>
                <tr>
                    <td colspan="5"><?php echo showPage($curr,$page);?></td>
                </tr>
            <?php endif;?>
            </tbody>
        </table>
    </div>
</div>
</body>
<script type="text/javascript">

    function addUser(){
        window.location="addUser.php";
    }
    function editUser(id){
        window.location="editUser.php?id="+id;
    }
    function delUser(id){
        if(window.confirm("您确定要删除吗？删除之后不可以恢复哦！！！")){
            window.location="doAdminAction.php?act=delUser&id="+id;
        }
    }
</script>
</html>